<template>
  <div>
    <article class="innerPage bookList">
      <header class="breadcrumb">
        <x-breadcrumb :path="$route.path" :title="$route.meta.breadcrumb" :startIndex="$route.meta.startIndex">
        </x-breadcrumb>
      </header>
      <section>
        <div style="height:20px;"></div>
        <Addfrom :fromData="fromData" @btn_submit="btn_submit"></Addfrom>
      </section>
    </article>
  </div>
</template>

<script>
import Addfrom from '../components/form.vue'
export default {
  name: 'AdminIndex',
  components: {
    Addfrom
  },
  data() {
    return {
      fromData: {
        type: 1,
        img: '',
        name: '',
        link: '',
        is_play: 1,
        imgurl: ''
      }
    }
  },

  mounted() { },
  activated() {
    if (this.$route.query.action) {
      if (this.$route.query.action != 'refresh') {
        this.fromData = this.$options.data().fromData
      }
    } else {
      this.fromData = this.$options.data().fromData
    }
    this.setPageTabs()
  },
  methods: {
    btn_submit(e) {
      console.log(e)
      this.postData()
    },
    async postData() {
      try {
        let res = await this.request({
          url: '/admin/banner/add',
          method: 'post',
          loading: true,
          data: {
            name: this.fromData.name,
            img: this.fromData.img,
            link: this.fromData.link,

            skip_way: this.fromData.skip_way,
            sort: this.fromData.sort,
            big_type_id: this.fromData.big_type_id,
          }
        })
        if (res) {
          this.$message.success('添加成功')
          let that = this
          setTimeout(() => {
            that.pageTurnParams('PublicBanner', { action: 'refresh' })
          }, 2000)
        }
      } catch (err) {
        this.errorHandler(err)
      }
    }
  }
}
</script>

<style lang="scss" scoped></style>
